$(document).ready(function(){
	$("#pageFormContent2_SP").hide();
	$("#pageFormContent3_SP").hide();
	$("#priceTab1_SP").hide();
	$("#priceTab2_SP").hide();
	var tdRow = $("#tdFenquses_SP");	//横向- tr
	var priceSty;	//风格
	$("#theNextBtn_SP").click(function(){
		priceSty = $("input[name='priceSty']:radio:checked").val();
		var returnNum = checkContext();
		if(returnNum == 0){
			//文本域扩大基数：*16
			$.post("../partitionJson!findEPartitions.action",{"channelNumber":$("#channelNum_import_SP").val()},function(data){
				if(priceSty == 0){
					//横向
					tdRow.append("<td height='20' class='pricetdClass'><div style='width:130px;height:20px;line-height:20px;text-align:center;'>重量阶段</div></td>");
					$(data.epartitions).each(function(){
						tdRow.append("<td width='200' height='20' class='pricetdClass'>"+this.partition_name+"</td>");
					});
					$("#priceContext1_SP").attr("cols",(tdRow.children('td').size()) * 16);
//					document.getElementById("priceContext1td").rowspan = 45;
					$("#priceTab1_SP").show("slow");
				}else{
					//纵向
//					document.getElementById("priceContext1td").rowspan = 0;
					$("#priceTab2_SP").append("<tr>" +
					"<td height='20' class='pricetdClass'><div style='width:130px;height:20px;line-height:20px;text-align:center;'>重量阶段</div></td>" +
					"<td height='20' id='tdwidthaa_SP' width='100' rowspan='15'><textarea name='priceContext' rows='8' id='priceContext2_SP' cols='200'></textarea></td>"+
					"</tr>");
					var ii = 0;	//文本域行数 *2
					$(data.epartitions).each(function(){
						$("#priceTab2_SP").append("<tr>" +
						"<td height='20' width='100' class='pricetdClass'>" +
						this.partition_name +"</td>"+"</tr>");
						ii++;
					});
					$("#tdwidthaa_SP").attr("rowspan",ii+1);
					$("#priceContext2_SP").attr("rows", (ii)*1.4);
					$("#priceTab2_SP").show("slow");
				}
			});
			$("#sfenquName_SP").attr("value",sfenqu.innerText);
			$("#clientClassName_SP").attr("value",kehulei);
			$("#pageFormContent1_SP").fadeOut("normal");
			$("#pageFormContent2_SP").show("slow");
		}else{
			switch(returnNum){
				case 1:
					alertMsg.error("请选择起始分区");
					break;
				case 2:
					alertMsg.error("请选择客户编码");
					break;
//				case 3:
//					alertMsg.error("请选择报价类型");
//					break;
				case 4:
					alertMsg.error("请选择生效日期");
					break;
				case 5:
					alertMsg.error("请选择结束日期");
					break;
				case 6:
					alertMsg.error("请正确选择结束日期");
					break;
			}
		}
	});
	$("#theBackBtn_SP").click(function(){
		$("#pageFormContent2_SP").fadeOut("normal");
		$("#priceTab1_SP").hide();
		tdRow.children('td').remove();
		$("#priceContext1_SP").attr("value","");
		$("#priceTab2_SP").children('tr').remove();
		$("#priceTab2_SP").hide();
		$("#pageFormContent1_SP").show("slow");
	});
	$("#theSecondNextBtn_SP").click(function(){
		var priceContext ;
		if(priceSty == 0){
			priceContext = $("#priceContext1_SP").val();
		}else{
			priceContext = $("#priceContext2_SP").val();
		}
		$.post("../specialPrice_engenderPriceTable.action",{"priceSty":priceSty,"priceContext":priceContext},function(priceses){
			if(priceSty==0){
				$("#priceTable_SP").attr("width","1230");
			}else{
				$("#priceTable_SP").attr("width","1230");
			}
			$("#priceTableBody_SP").html(priceses);
		});
		
		$("#pageFormContent2_SP").fadeOut("normal");
		$("#pageFormContent3_SP").show("slow");
	});
	$("#theSecondBackBtn_SP").click(function(){
		
		$("#pageFormContent3_SP").fadeOut("normal");
		$("#pageFormContent2_SP").show("slow");
		$("#priceTableBody_SP").html("");
	});
	
	$("#handleFareIn_SP").hide();
	$("#handleFare_SP").click(function(){
		if($("#handleFare_SP").attr("checked")){
			$("#handleFareIn_SP").show("slow");
			$("#handleFareIn_SP").attr("value",$("#handleFare_im_SP").val());
		}else{
			$("#handleFareIn_SP").fadeOut("normal");
			$("#handleFareIn_SP").attr("value","0");
		}
	});
	$("#registerFareIn_SP").hide();
	$("#registerFare_SP").click(function(){
		if($("#registerFare_SP").attr("checked")){
			$("#registerFareIn_SP").show("slow");
			$("#registerFareIn_SP").attr("value",$("#registerFare_im_SP").val());
		}else{
			$("#registerFareIn_SP").fadeOut("normal");
			$("#registerFareIn_SP").attr("value","0");
		}
	});
	$("#otherFareIn_SP").hide();
	$("#otherFare_SP").click(function(){
		if($("#otherFare_SP").attr("checked")){
			$("#otherFareIn_SP").show("slow");
			$("#otherFareIn_SP").attr("value",$("#otherFare_im_SP").val());
		}else{
			$("#otherFareIn_SP").fadeOut("normal");
			$("#otherFareIn_SP").attr("value","0");
		}
	});
	
	$("#findCustomerNum_SP").click(function(){
		asyncbox.open({
			url : "../specialPrice_readfindCustomers.action",
			width : 950,
			height : 450,
			top : 65,
			drag : false,
			modal : true,
			scrolling : "yes",
			title : "客户信息",
			tipsbar : {
				title : '客户信息查询',
				content : '客户信息查询'
			},
			btnsbar : $.btn.OKCANCEL,
			callback : function(action,iframe,returnValue){
				if(action == 'ok'){
					var strs = returnValue.split("|:,:|");
					$("#customerNum_SP").attr("value",strs[0]);
				}else{
					
				}
			}
		});
	});
});

var sfenqu ;
var kehulei	;
//var baojialei ;
function checkContext() {
		sfenqu = $("#sfenqu_SP option:selected").get(0);
		kehulei = $("#customerNum_SP").val();
	//	baojialei = $("#baojiaTypes option:selected").get(0);
		if(sfenqu.value == ""){
			return 1;
		}else if(kehulei == ""){
			return 2;	
		}
//		else if(baojialei.value == -1){
//			return 3;
//		}
		else if($("#priceStartDate_SP").val() == ""){
			return 4;
		}else if($("#priceEndDate_SP").val() == ""){
			return 5;
		}else if($("#priceEndDate_SP").val() <= $("#priceStartDate_SP").val()){
			return 6;
		}else{
			return 0;
		}
		
	}
function zhuanhuan(str){
	while(!(parseFloat(str) > 0)){
		str = str.substring(1,str.length);
	}
	return parseFloat(str);
}